const app = getApp()

Page({
  data: {

    loading:true,
    cate_sid:0,
  },

  param: {
    page:0,
    cate_id:0,
  },

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
    app.getParam(options,param =>{
      wx.setNavigationBarTitle({
        title: param.title,
      })
      this.param.cate_id = param.cate_id;
      this.setData({
        cate_sid:parseInt(param.cate_sid)
      })
      app.isLbs((rel)=>{
        this.setData({
          lat:app.globalData.lbs.lat,
          lng:app.globalData.lbs.lng
        })
        this.getCate();
      })
    })
  },
  //获取API
  getCate: function () {
    app.api().Get('api/v1/ais/store/cate',{cate_id:this.param.cate_id},(result) => {
      if (result.code == 200) {
        this.setData({
          cate:result.data
        });
        this.getStore();
      }
    })
  },
	//获取商品列表
	getStore: function () {
    if (this.data.loading) {
      var param =  {
        page: this.param.page+1,
        cate_id:this.param.cate_id,
        cate_sid:this.data.cate_sid,
        citycode:app.globalData.location.adcode
      }
      app.api().Get('api/v1/ais/store/index',param,(result) => {
        if (result.code == 200) {
          this.setData({
            stores: result.data,
          })
          this.param.page = param.page;
        }
      })
      this.setData({
        loading: false
      })
    }

	},
  //点击Tab栏目切换
  onClickTab: function (event) {
    this.setData({
      cate_sid: parseInt(event.detail.name),
      loading: true,
      stores: [],
    });
    this.param.page = 0;
    this.getStore();
  },
})